$().ready(function() {
    getMarshallingByUpdate(null)
	validateRule();
});

$.validator.setDefaults({
	submitHandler : function() {
		save();
	}
});
function save() {
    var formData = new FormData($("#signupForm")[0]);
	$.ajax({
		cache : false,
		type : "POST",
		url : getProjectName()+"/staff/staff/save",
		data : formData,// 你的formid
		async : false,
        contentType: false,
        processData: false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				parent.layer.alert(data.msg)
			}

		}
	});

}
function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
            staffName : {
				required : true
			},
            age : {
                required : true
            },
            entryDate : {
                required : true
			},
            education : {
                required : true
            },
            file : {
                required : true
            },
            deptName : {
                required : true
            },
            brand : {
                required : true
            },
            factory : {
                required : true
            }

		},
		messages : {
            staffName : {
				required : icon + "请输入姓名"
			},
            age : {
                required : icon + "请输入年龄"
            },
            entryDate : {
                required : icon + "请输入入职时间"
            },
            education : {
                required : icon + "请输入学历"
            },
            file : {
                required : icon + "请上传文件"
            },
            deptName : {
                required : icon + "请选择部门"
            },
            brand : {
                required : icon + "请填写品牌"
            },
            factory : {
                required : icon + "请填写厂家"
            }
		}
	})
}

function loadDept( deptId,deptName){
    $("#deptId").val(deptId);
    $("#deptName").val(deptName);
}